With coming of a mobile Internet era, a mainstream pattern in the Internet industry becomes social, localized, and mobile. Particularly, with popularization of a mobile device equipped with a Wireless Fidelity (Wireless-Fidelity, Wi-Fi) interface, social application of a device in neighbor awareness networking (Neighbor Awareness Networking, NAN) is becoming a hot spot in the industry.
A NAN network including multiple NAN devices is referred to as a NAN cluster (Cluster), and devices in a same NAN cluster have a same cluster identifier. Each device has its own attributes, including: a role (Role) and a state (State). A role includes two types: master (Master) and non-master (non-Master), and a state includes two types: synchronization (sync) and non-synchronization (non-sync). A device in the sync state is responsible for maintaining cluster synchronization. A master must be in the sync state, but a non-master may be in a sync or non-sync state. Each device further includes a master rank (Master Rank, MR), a master with a largest MR in the NAN cluster becomes an anchor master (Anchor Master, AM), and all other devices keep time synchronous with the AM, thereby ensuring synchronization of the entire NAN cluster.
A typical application scenario in the NAN cluster is that devices perform mutual service discovery before being associated. To perform service discovery between devices, a device in the NAN cluster must work on a social (social) channel of the NAN in a specific time period and maintain an awake (awake) state, for example, a social channel on a 2.4 GHz frequency channel is a channel 6. In some scenarios, the NAN is required to run in a background for a long time, and therefore a device in the NAN needs to perform energy saving control. Therefore, the device awakes only when a discovery window (Discovery Window, DW) arrives, and performs service discovery and cluster synchronization on a social channel; however, outside a DW, all devices except the master may be in a sleep state.
Because crystal oscillators inside different NAN devices have different frequencies, two devices must be often synchronized so as to ensure that there is no large deviation between system clocks of the two devices. To maintain synchronization of the NAN cluster, each master and each sync non-master send a synchronization beacon (Sync Beacon) frame in a DW, where the synchronization beacon frame includes AM information and time synchronization function (Time Synchronization Function, TSF) information, and the AM information includes: an anchor master rank (Anchor Master Rank, AMR), a hop count (Hop Count to Anchor Master, HC), and an anchor master beacon transmission time (Anchor Master Beacon Transmission Time, AMBTT). The AMR is an MR value of an AM, and each device in the NAN cluster records an AMR value.
Because a synchronization reference in the NAN cluster is the AM, that is, the master with the largest MR, and the MR changes randomly with time, when an MR of a device changes, the master with the largest MR in the NAN cluster also changes. When the MR of the device changes, an AM with a largest MR can be selected in time in the NAN cluster, which is crucial for maintaining synchronization of the NAN cluster. According to a current NAN specification draft, in a process of NAN cluster synchronization, an AMR value recorded in a device only becomes larger. However, when an MR of an AM becomes smaller, even if a device whose MR is an original AMR value does not exist, the original AMR value recorded in the device always exists in the NAN cluster and cannot be removed, and a recorded HC value becomes larger. According to an existing specification, when an HC in a received Sync Beacon frame exceeds a threshold, a device discards the Sync Beacon frame, that is, as time goes by, an HC becomes larger, devices in the entire NAN cluster discard all received Sync Beacon frames because the HC exceeds the threshold. Moreover, because the NAN cluster loses an AM, the entire NAN cluster crashes, and as a result, time synchronization between the devices cannot be implemented.